package Operations;

import Book.book;
import Book.bookList;

import java.util.Scanner;

public class DeletOperation implements Ioperations{
    @Override
    public void work(bookList bookList) {
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入你要删除的书名");
        String name=scanner.nextLine();
        //用遍历的方式查询书架中是否存在输入的书名
        int i=0;
        int used=bookList.getUseMount();
        for (;i <used; i++) {
            //用bookList已写的方法获取下标为i的书对象
            book book=bookList.getBooks(i);
            if(book.getName().equals(name)){
                System.out.println("该书找到了");
                System.out.println(book);
                for (int j = i; j < bookList.getUseMount()-1; j++) {
                    bookList.setBooks(i,bookList.getBooks(i+1));
                }
                //将书架中的书籍数减少1
                bookList.setUseMount(used-1);
                System.out.println("删除书籍成功");

                return;
            }
        }

        System.out.println("抱歉该书不存在");
    }
}
